package com.hundsun.yr.universal.p2p.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.data.HSSharedPreferences;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils.NetType;
import com.hundsun.yr.universal.library.widget.GestureLockView;
import com.hundsun.yr.universal.library.widget.GestureLockView.OnCompleteListener;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.config.Config;
import com.hundsun.yr.universal.p2p.config.Config.SPPath;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;

/**
 * GestureLockVerify2Activity与GestureLockVerifyActivity有非常大的不同
 * 所以不复用GestureLockVerifyActivity
 */
public class GestureLockVerify2Activity extends BaseActivity implements OnClickListener {

    private GestureLockView gesture_view;
    private TextView tips;
    private TextView tvForgetGesture;

    private HSSharedPreferences mConfigSP;
    private ImageView img_gesture_close;

    private int openflag;
    private int gestureOpen = 1;
    private int gestureClose = 2;

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_gestureverify;
    }

    @Override
    protected void initViewsAndEvents() {
        findViews();
        img_gesture_close.setOnClickListener(this);
        tvForgetGesture.setVisibility(View.GONE);
        tips.setTextColor(Color.rgb(160, 162, 185));
        mConfigSP = new HSSharedPreferences(mContext, SPPath.file_configInfo);
        String result = mConfigSP.getShareProf(sharedPreferences.getShareProf(UserInfo.USER_NO) + Config.GESTURE);
        gesture_view.setKeySet(result);
        gesture_view.setOnCompleteListener(new OnCompleteListener() {

            @Override
            public void onError() {
            }

            @Override
            public void onComplete(String result) {
                if (openflag == gestureOpen) {
                    mConfigSP.putBoolean(sharedPreferences.getShareProf(UserInfo.USER_NO) + Config.IF_GESTURE, true);
                }
                if (openflag == gestureClose) {
                    mConfigSP.putShareProf(sharedPreferences.getShareProf(UserInfo.USER_NO) + Config.GESTURE, null);
                    mConfigSP.putBoolean(sharedPreferences.getShareProf(UserInfo.USER_NO) + Config.IF_GESTURE, false);
                }
                finish();
            }
        });
    }

    private void findViews() {
        gesture_view = findView(R.id.verify_gesture_view);
        tips = findView(R.id.gesture_verify_tips);
        tvForgetGesture = findView(R.id.tv_forget_gesture);
        img_gesture_close = findView(R.id.img_gesture_close);

    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        openflag = extras.getInt("openflag");
    }

    @Override
    protected void onEveComming(@SuppressWarnings("rawtypes") EventCenter eventCenter) {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void onNetworkConnected(NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return true;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.img_gesture_close:
                finish();
                break;
        }
    }

}
